package com.bolehui.web;

import com.bolehui.base.result.Result;
import com.bolehui.base.utils.SecurityUtil;
import com.bolehui.domain.dto.UserDTO;
import com.bolehui.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author chendongjie     email:chendongjie@gz.iscas.ac.cn
 * @version 1.0
 * @ClassName userController
 * @Description 用户表现层
 * @createTime 2024/11/29 10:14
 * Copyright (C) 2021-2022 CASEEDER, All Rights Reserved.
 * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的
 */
@RestController
@RequestMapping("/login.do")
public class LoginController {

    @Autowired
    private UserService userService;

    /**
     * 登录
     * @param dto
     * @return
     */
    @RequestMapping(params = "action=login")
    public Result login(@RequestBody  UserDTO dto){
        return userService.login(dto);
    }

    /**
     * 注册
     */
    @RequestMapping(params = "action=registered")
    public Result registered(@Valid UserDTO dto){
        return userService.registered(dto);
    }

    /**
     * 修改密码
     */
    @RequestMapping(params = "action=modifyPassword")
    public Result modifyPassword(Long userId, String oldPassword, String newPassword){
        if(userId == null){
            userId = SecurityUtil.getCurrentUserId();
        }
        return userService.modifyPassword(userId, oldPassword, newPassword);
    }


}
